package a07_二叉树;

/**
 * <p>
 * a21_合并二叉树复习2
 * </p>
 *
 * @author flyduck
 * @since 2025/2/20
 */
public class a21_合并二叉树复习2 {
    public TreeNode mergeTrees(TreeNode root1, TreeNode root2) {
        if (root1 == null && root2 == null) {
            return null;
        }else if(root1 != null && root2 == null){
            return root1;
        }else if(root1 == null && root2 != null){
            return root2;
        }
        TreeNode rootNode = new TreeNode(root1.val + root2.val);
        rootNode.left = mergeTrees(root1.left, root2.left);
        rootNode.right = mergeTrees(root1.right, root2.right);
        return rootNode;
    }
}
